package hacker_rank._101hackfeb;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class SherlockPairs {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int T = Integer.parseInt(br.readLine());
		
		for(int t = 0; t < T; t++) {
			int N = Integer.parseInt(br.readLine());
			String[] line = br.readLine().split(" ");
			
			int[]nums = new int[N];
			for(int i = 0; i < N; i++) {
				nums[i] = Integer.parseInt(line[i]);
			}
			solve(nums);
		}
		
	}

	private static void solve(int[] nums) {
		Map<Integer, Long> freqMap = new HashMap<Integer, Long>();
		

		for(Integer n : nums) {
			Long c = freqMap.get(n);
			if(c == null)
				c = 0L;
			
			freqMap.put(n, c + 1);
		}
		long res = 0;
		for(Map.Entry<Integer, Long> e : freqMap.entrySet()) {
			if(e.getValue() > 1)
				res += e.getValue() * (e.getValue() -1);
		}
		System.out.println(res);
		
	}
}
